{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "邮件发送成功\n"
     ]
    }
   ],
   "source": [
    "import smtplib\n",
    "from email.mime.text import MIMEText\n",
    "from email.header import Header\n",
    " \n",
    "# 第三方 SMTP 服务\n",
    "mail_host=\"smtp.qq.com\"  #设置服务器\n",
    "mail_user=\"1367575492@qq.com\"    #用户名\n",
    "mail_pass=\"dtbrgmyixupfhfde\"   #口令 \n",
    " \n",
    " \n",
    "sender = '1367575492@qq.com'  # 发件邮箱\n",
    "receivers = ['1367575492@qq.com']  # 接收邮箱\n",
    "\n",
    "# file_html = open('funnel_chart.html','rb')\n",
    "# data = file_html.read()\n",
    "\n",
    "# 发送文本内容\n",
    "\n",
    "message = '上月运维单分析'\n",
    "message = MIMEText(message, 'plain', 'utf-8')\n",
    "\n",
    "# 发送HTML内容\n",
    "# message = \"\"\"\n",
    "# <p>Python 邮件发送测试...</p>\n",
    "# <p><a href=\"http://www.runoob.com\">菜鸟教程链接</a></p>\n",
    "# <p>图片演示：</p>\n",
    "# <p><img src=\"cid:image1\"></p>\n",
    "# \"\"\"\n",
    "# message = MIMEText(message, 'html', 'utf-8')\n",
    "\n",
    "message['From'] = Header(\"测试\", 'utf-8')  # 发件人昵称\n",
    "message['To'] =  Header(\"\", 'utf-8')   # 收件人\n",
    " \n",
    "subject = 'Python SMTP 邮件测试'\n",
    "message['Subject'] = Header(subject, 'utf-8')\n",
    " \n",
    "try:\n",
    "    smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 465 为 SMTP 端口号\n",
    "    smtpObj.login(mail_user,mail_pass)\n",
    "    smtpObj.sendmail(sender, receivers, message.as_string())\n",
    "    print (\"邮件发送成功\")\n",
    "    smtpObj.quit() \n",
    "except smtplib.SMTPException:\n",
    "    print (\"Error: 无法发送邮件\")"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "f0831691c6bb6c483f09af1e7987fd76373eadc68cb706017f41b090bfe4d138"
  },
  "kernelspec": {
   "display_name": "Python 3.8.3 64-bit ('base': conda)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
